#include <bits/stdc++.h>
using namespace std;

long long num;
int base;

int main()
{
    string s = "0123456789ABCDEF";
    string ans;
    cin >> num >> base;
    while (num)
    {
        ans += s[num % base];
        num /= base;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    return 0;
}

